<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html" ; charset="utf-8" />
    <title>预约查询</title>
    <link href="../../../css/main.css" rel="stylesheet" type="text/css" />
    <link
      href="../../../bstable/css/bootstrap.min.css"
      rel="stylesheet"
      type="text/css"
    />
    <link
      href="../../../bstable/css/bootstrap-table.css"
      rel="stylesheet"
      type="text/css"
    />
    <style>
      .dialog-form {
        width: 350px;
      }

      .dialog-form .form_input {
        width: 50%;
      }

      .dialog-form .form-control {
        width: 74%;
        display: inline-block;
      }

      .dialog-form .p_line {
        border: none;
      }
    </style>
  </head>

  <body>
    <div class="tabe_div">
      <p
        class="p_line text_ient"
        style="margin-bottom: -10px; border-bottom: 0"
      >
        <a class="find_a">姓名：</a>
        <input
          type="text"
          id="studentName"
          class="form_input text_ient"
          placeholder="输入姓名"
        />
        <a class="find_a">客户类型：</a>
        <select class="form_select" style="padding-left: 1%" id="customType">
          <option value="">请选择</option>
          <option value="1">意向客户</option>
          <option value="2">一般客户</option>
          <option value="3">成交客户</option>
          <option value="0">其他</option>
        </select>
        <a class="find_a">创建时间：</a>
        <input
          id="insertTime"
          type="date"
          class="input-70 form_input text_ient"
          placeholder=""
        />
        <a class="find_a">意向报考类型：</a>
        <select class="form_select" style="padding-left: 1%" id="preType">
          <option value="">请选择</option>
          <option value="1">学历提升</option>
          <option value="2">职业技能</option>
          <option value="3">职称评审</option>
          <option value="4">执业资格</option>
        </select>
        <input type="button" value="查询" class="but_find" id="search" />
      </p>
      <table
        data-url="json/data_alae_list.json"
        id="table"
        class="table_style"
        style="margin: 20px auto"
      ></table>
    </div>
    <script src="../../../js/jquery.js"></script>
    <script src="../../../js/common.js"></script>
    <script src="../../../js/laydate-master/laydate.js"></script>
    <script src="../../../bstable/js/bootstrap.min.js"></script>
    <script src="../../../bstable/js/bootstrap-table.js"></script>
    <script src="../../../bstable/js/bootstrap-table-zh-CN.min.js"></script>
    <script type="text/javascript">
      localStorage.setItem('name', '客户管理/预约查询');
      var pageNumber =
        location.search == '' ? 0 : location.search.split('=')[1];
      $(function () {
        openMsg();
        $('#search').on('click', function () {
          $('#table').bootstrapTable('refresh');
        });
        $('#merge').on('click', function () {
          const selects = $('#table')
            .bootstrapTable('getSelections')
            .map((item) => {
              return item;
            });

          console.log(`selects`, selects);

          // $.ajax({
          //   url: baseUrl + 'preStudent/mergePreStudent',
          //   method: 'post',
          //   headers: {
          //     Authorization: JSON.parse(localStorage.getItem('userInfo')).token,
          //   },
          //   data: {
          //     list: selects.toString(),
          //   },
          //   success: function (data) {
          //     $('#table').bootstrapTable('refresh');
          //     alert('提交成功');
          //   },
          // });
        });
        $('#group').on('click', function () {
          const selects = $('#table')
            .bootstrapTable('getSelections')
            .map((item) => {
              return item.id;
            });
          $.ajax({
            url: baseUrl + 'preStudent/toTeam',
            method: 'post',
            headers: {
              Authorization: JSON.parse(localStorage.getItem('userInfo')).token,
            },
            data: {
              id: selects[0],
            },
            success: function (data) {
              $('#table').bootstrapTable('refresh');
              alert('提交成功');
            },
          });
        });
        $('#common').on('click', function () {
          const selects = $('#table')
            .bootstrapTable('getSelections')
            .map((item) => {
              return item.id;
            });
          $.ajax({
            url: baseUrl + 'preStudent/toPublic',
            method: 'post',
            headers: {
              Authorization: JSON.parse(localStorage.getItem('userInfo')).token,
            },
            data: {
              id: selects[0],
            },
            success: function (data) {
              $('#table').bootstrapTable('refresh');
              alert('提交成功');
            },
          });
        });
        $('#create').on('click', function () {
          window.location.href = '../student/customer-form.html';
        });
        var perm = JSON.parse(localStorage.getItem('userInfo')).perm;
        $('#table').bootstrapTable({
          method: 'get',
          striped: true,
          singleSelect: false,
          url: baseUrl + 'preStudent/getPrivate',
          dataType: 'json',
          // rowStyle:rowStyle,
          pagination: true, //分页
          sidePagination: 'server',
          pageSize: 10,
          pageNumber: Number(pageNumber) + 1,
          search: false, //显示搜索框
          contentType: 'application/x-www-form-urlencoded',
          ajaxOptions: {
            headers: {
              Authorization: JSON.parse(localStorage.getItem('userInfo')).token,
            },
          },
          queryParams: function (params) {
            params.studentName = $('#studentName').val();
            params.customType = $('#customType').val();
            params.insertTime = $('#insertTime').val();
            params.recorderTime = $('#recorderTime').val();
            params.preType = $('#preType').val();
            params.queryPre = 'queryPre';
            params.offset = params.offset / params.limit;
            pageNumber = params.offset;
            delete params.order;
            return params;
          },
          responseHandler: function (res) {
            var list = res.data.records;
            return {
              rows: list,
              total: res.data.total,
            };
          },
          columns: [
            {
              checkbox: true,
              width: 80,
            },
            {
              field: 'no',
              title: '序号',
              sortable: true,
              align: 'center',
              formatter: function (value, row, index) {
                var pageSize =
                  $('#table').bootstrapTable('getOptions').pageSize;
                var pageNumber =
                  $('#table').bootstrapTable('getOptions').pageNumber;
                return pageSize * (pageNumber - 1) + index + 1;
              },
            },
            {
              title: '姓名',
              field: 'studentName',
              align: 'center',
              valign: 'middle',
            },
            {
              title: '跟进人',
              field: 'teacherName',
              align: 'center',
            },
            {
              title: '意向报考类型',
              field: 'preType',
              formatter: function (value, row, index) {
                switch (value) {
                  case '1':
                    return '学历提升';
                  case '2':
                    return '职业技能';
                  case '3':
                    return '职称评审';
                  case '4':
                    return '执业资格';
                }
              },
              align: 'center',
            },
            {
              title: '客户创建时间',
              field: 'insertTime',
              align: 'center',
            },
            {
              title: '客户类型',
              field: 'customType',
              formatter: function (value, row, index) {
                switch (value) {
                  case '1':
                    return '意向客户';
                  case '2':
                    return '一般客户';
                  case '3':
                    return '成交客户';
                  case '0':
                    return '其他';
                }
              },
              align: 'center',
            },
            {
              title: '最后修改时间',
              field: 'updateTime',
              align: 'center',
            },
            {
              title: '操作',
              field: 'id',
              align: 'center',
              width: '200',
              formatter: function (value, row) {
                var a =
                  '<a href="#" onclick="look(\'' + row.id + '\')">查看</a> ';

                var b =
                  '<a href="#" style="margin-left:8px" onclick="refund(\'' +
                  row.id +
                  '\')">预约</a> ';

                return a + b;
              },
            },
          ],
        });
      });

      function saveGroup(id) {
        console.log('新增');
        var formData = new FormData();
        var gjzt = $('#gjzt').val();
        var yysj = $('#yysj').val();
        var rwms = $('#rwms').val();
        if (!gjzt) {
          alert('请选择跟进状态');
          return false;
        }
        if (!yysj) {
          alert('请选择预约时间');
          return false;
        }
        // if (id) {
        //   formData.append('preStudentId', id);
        //   formData.append('status', gjzt);
        //   formData.append('pre_time', yysj);
        //   formData.append('note', rwms);
        // }
        var data = {
          preStudentId: id,
          status: gjzt,
          pre_time: yysj,
          note: rwms,
        };
        $.ajax({
          url: baseUrl + 'preStudent/addRecorder',
          method: 'post',
          headers: {
            Authorization: JSON.parse(localStorage.getItem('userInfo')).token,
          },
          contentType: 'application/json;charset=UTF-8',
          data: JSON.stringify(data),
          // mimeType: 'multipart/form-data',
          success: function (response) {
            if (response.code === 200) {
              layer.close(1);
              $('#table').bootstrapTable('refresh');
            }
          },
        });
      }

      function look(id, idNo, flag, trainType, studyId, commitFlag) {
        window.location.href = `../student/customer-form.html?id=${id}&backName=reserve&isLook=edit`;
      }

      function refund(id) {
        var html = `<div class="dialog-form"><div class="p_line text_ient lx-row">
                            <p class="col lx-col-50">
                    <a class="find_a">跟进状态：</a>
                    <select id="gjzt" class="form_input text_ient">
                      <option selected="" value="1">初步沟通</option>
            <option value="2">持续跟进</option>
            <option value="3">方案分析</option>
            <option value="4">制定方案</option>
            <option value="5">成交</option>
            <option value="6">跟进失败</option>
        </select>
                </p>
                <p class="col lx-col-50">
                    <a class="find_a">
                        预约时间：</a>
                    <input id="yysj" type="date" class="form_input text_ient" />
                </p>
                <p class="col lx-col-50">
                    <a class="find_a">任务描述：</a>
                    <input type="text" id="rwms" class="form-control text_ient" placeholder="" value=""/>
                </p>
            </div></div>`;
        layer.open({
          title: '预约信息',
          type: 1,
          // closeBtn: 0, //不显示关闭按钮
          anim: 2,
          yes: function (index, layero) {
            saveGroup(id);
          },
          btn: ['确认'],
          // shadeClose: true, //开启遮罩关闭
          content: html,
        });
      }
    </script>
  </body>
</html>
